package com.yz.xyt.controller;

import com.yz.xyt.domain.ResponseResult;
import com.yz.xyt.domain.User;
import com.yz.xyt.domain.vo.UserVo;
import com.yz.xyt.service.ILoginService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * 登录controller
 */
@RestController
@RequestMapping("/user")
public class LoginController {

    @Autowired
    ILoginService loginService;

    /**
     * 用户登录
     * @param user
     * @return
     */
    @RequestMapping("/login")
    public ResponseResult login(UserVo user){
        ResponseResult login = loginService.login(user);
        return login;
    }

    /**
     * 三方登录
     * @param user
     * @return
     */
    @PostMapping("/thirdPartyLogin")
    public ResponseResult thirdPartyLogin(@RequestBody User user){
        ResponseResult login = loginService.thirdPartyLogin(user);
        return login;
    }

    /**
     * 退出登录
     * @return
     */
    @RequestMapping("/logout")
    public ResponseResult logout(){
        ResponseResult logout = loginService.logout();
        return logout;
    }
}
